home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0181_Compensating for different screen resolu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-29  |  1.9 KB  |  65 lines

  1. {
  2. My forms always look bad when displayed at a screen resolution different
  3. from the one it was designed at. I found some code in Lloyd's help file,
  4. which made it look very easy. The only problem is that it won't compile for
  5. me. The code is as follows:
  6.  
  7. ------------------------------------------------ }
  8.  
  9. implementation
  10. const
  11.   ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}
  12.   ScreenHeight: LongInt = 600;
  13.  
  14. {$R *.DFM}
  15.  
  16. procedure TForm1.FormCreate(Sender: TObject);
  17. var
  18.   i, OldFormWidth: integer;
  19. begin
  20.   scaled := true;
  21.   if (screen.width <> ScreenWidth) then begin
  22.     OldFormWidth := width;
  23.     height := longint(height) * longint(screen.height) DIV ScreenHeight;
  24.     width := longint(width) * longint(screen.width) DIV ScreenWidth;
  25.  
  26.     scaleBy(screen.width, ScreenWidth);
  27.     font.size := (Width DIV OldFormWidth) * font.size;
  28.   end;
  29. end;
  30.  
  31.  
  32. Then, you will want to have something that checks to see that  the font
  33. sizes are OK.  Before you change the font's size, you  would need to ensure
  34. the object actually has a font property by checking the RTTI.   This can be
  35. done as follows:
  36.  
  37. USES TypInfo;  {Add this to your USES statement.}
  38.  
  39. var
  40.   i: integer;
  41. begin
  42.   for i := componentCount - 1 downto 0 do
  43.     with components[i] do
  44.     begin
  45.       if GetPropInfo(ClassInfo, 'font') <> nil  then
  46.         font.size := (NewFormWidth DIV OldFormWidth) * font.size;
  47.  
  48.     end;
  49. end;
  50.  
  51.  
  52. ------------------------------------------------
  53.  
  54. The first problem is that the TypeInfo unit does not seem to exist. The
  55. other problem is that the GetPropInfo() function is undefined. Apparently
  56. it is in the TypeInfo unit. What am I missing? Has the TypeInfo class been
  57. removed from Delphi in version 2? Is there another way to find out if a
  58. component has a Font property? Please help!
  59.  
  60. Thanks,
  61. David Novak
  62. novak@valu-line.net
  63. Delphi 2.01, Win95
  64.  
  65.